home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2740 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: howland.reston.ans.net!gatech!udel!usenet
  2. From: finkcr1@ptu-crf-pc.jhuapl.edu
  3. Newsgroups: comp.os.ms-windows.programmer.graphics,comp.lang.c++
  4. Subject: Saving a DIB to a file
  5. Date: Fri, 19 Jan 96 07:35:46 PDT
  6. Organization: University of Delaware
  7. Message-ID: <NEWTNews.822065811.24940.finkcr1@ptu-crf-pc.jhuapl.edu>
  8. NNTP-Posting-Host: ptu-crf-pc.jhuapl.edu
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11. X-Newsreader: NEWTNews & Chameleon -- TCP/IP for MS Windows from NetManage
  12.  
  13.  
  14. I'm using VC++ 1.5 and have successfully saved the image I drew in an MDI 
  15. child window to a file as a DIB.  I used as a model the code in the MS example 
  16. program DIBVIEW.  The problem is that the bitmap I've saved to the file shows 
  17. up as a monochrome bitmap; the colors displayed in the window do not show up. 
  18. Here is the code I used to copy the bitmap to a memory DC:
  19.  
  20.     memDC.CreateCompatibleDC(GetDC())
  21.                      .
  22.              .    
  23.         bm.CreateCompatibleBitmap(&memDC,rect.Width(),rect.Height());
  24.                  .
  25.              .        
  26.        oldbm = memDC.SelectObject(&bm);
  27.        memDC.BitBlt(0, 0, rect.Width(),rect.Height(), GetDC(), 0, 0, SRCCOPY); 
  28.  
  29.  
  30. When I do a GetObject on the bitmap, it says it has 1 bit per pixel.  I'm 
  31. confused. I don't completely understand the intricacies of palettes, etc.. The 
  32. palette associated with the memory DC seems to be OK (20 entries). I call a 
  33. routine, WinDibFromBitmap (copied from DIBVIEW), it calls GetDibBits and 
  34. passes back a handle to the DIB.  It also sets up the BITMAPINFO header and 
  35. allows space for the color table.  It sets the BiBitCount entry in the 
  36. BITMAPINFOHEADER to a value calculated from the product of the BmPlanes and 
  37. BmBitsPixel entries in the BITMAP structure.  BiBitCount is then used to 
  38. determine the number of entries in the color table. The palette is passed to 
  39. the routine as an HPALETTE structure. This is selected into a DC and then 
  40. RealizePalette is called. This DC (Creates with a GetDC(NULL)) is used as a 
  41. parameter to GetDibBits.   
  42.  
  43. If there are any DIB experts out there, please respond to me at 
  44. finkcr1@jhuapl.edu or to one of these newsgroups.  Thanks.
  45.  
  46. Clay Fink 
  47.  
  48.  
  49.  
  50.